package com.huirui.server.controller.admin;

import com.huirui.server.pojo.entity.Zone;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.ZoneVo;
import com.huirui.server.service.ZoneService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminZoneController")
@RequestMapping("/admin/zone")
@Slf4j
@Validated
@Tag(name = "专区管理", description = "微信小程序专区管理")
public class ZoneController {

    @Resource
    private ZoneService zoneService;

    @GetMapping
    @Operation(summary = "获取专区列表")
    public Result<PageResult<ZoneVo>> listZoneItem(
            @RequestParam(value = "keyword", required = false) String keyword,
            Long page,
            Long pageSize
    ) {
        PageResult<ZoneVo> res = zoneService.listZoneItem(keyword, page, pageSize);
        return Result.success(res);
    }

    @PutMapping
    @Operation(summary = "修改专区条目")
    public Result<Void> updateZoneItem(Long categoryId, Integer status) {
        zoneService.updateZoneItem(categoryId, status);
        return Result.success();
    }

    @PostMapping
    @Operation(summary = "新增专区Item")
    public Result<Void> addZoneItem(Long categoryId, Integer status) {
        zoneService.addNewZoneItem(categoryId, status);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除专区Item")
    public Result<Void> deleteZoneItem(Long categoryId) {
        zoneService.deleteZoneItem(categoryId);
        return Result.success();
    }


}
